package com.kasif;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;


public class MainActivity extends FragmentActivity {
    private float baslangicX;
    private float baslangicY;
    private String baslangicTitle;
    private float varisX;
    private float varisY;
    private String varisTitle;

    int request_code_baslangic = 1;
    int request_code_varis = 2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();

        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    public void doRotaHesaplaClick(View v){
        Intent intent = new Intent(getApplicationContext(), MapActivity.class);
        startActivity(intent);

    }

    public void doKonumSecClick(View v){
        Intent intent = new Intent(getApplicationContext(), MapSecActivity.class);
        startActivityForResult(intent, request_code_baslangic);
    }

    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if(requestCode == request_code_baslangic){
            if(resultCode == RESULT_OK){
                Bundle bundle = data.getExtras();
                if (bundle != null) {
                    baslangicX = bundle.getFloat("latitude");
                    baslangicY = bundle.getFloat("longitude");
                    baslangicTitle = bundle.getString("title");
                }

                ((EditText) findViewById(R.id.editTextBaslangic)).setText(baslangicTitle);
                ((EditText) findViewById(R.id.editTextVaris)).setText(varisTitle);
            }
        }
    }
}
